import { http } from "@/utils"

/**
 * 获取频道列表
 */
export const getChannelListApi = () => {
  return http({
    url: "/channels",
    method: "GET",
  })
}

/**
 * @params {}
 * 获取文章列表
 */
export const getArticleListApi = (params) => {
  return http({
    url: "/mp/articles",
    params,
    method: "GET",
  })
}

/**
 *
 * @param {*} id 文章的唯一标识
 * @returns
 */
export const delAriticleApi = (id) => {
  return http({
    method: "delete",
    url: `/mp/articles/${id}`,
  })
}

/**
 *发布文章
 * @param {*} data 发布文章的参数
 * @returns
 */
export const saveArticleApi = (draft, data) => {
  return http({
    url: `/mp/articles?draft=${draft}`,
    method: "POST",
    data,
  })
}

/**
 *获取文章详情
 * @param {*} id 文章id
 * @returns
 */
export const getArticleInfoApi = (id) => {
  return http({
    url: `/mp/articles/${id}`,
    method: "GET",
  })
}

export const editArticleApi = (draft = false, data) => {
  return http({
    url: `/mp/articles/${data.articleId}`,
    method: "PUT",
    data,
    params: {
      draft,
    },
  })
}
